﻿namespace MefContrib.Models.Provider
{
    using System.Collections.Generic;
    using System.ComponentModel.Composition.Primitives;
    using System.Reflection;
    using MefContrib.Models.Provider.Validation;

    /// <summary>
    /// Defines an export required by a <see cref="ProviderComposablePart"/> object.
    /// </summary>
    public class ProviderExportDefinition : ExportDefinition
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ProviderExportDefinition"/> class, 
        /// using the specified values to define the export.
        /// </summary>
        /// <param name="member">The member that the exort is associated with.</param>
        /// <param name="contractName">The name of the contract that the export should associated with.</param>
        /// <param name="metadata">The metadata associated with the export.</param>
        public ProviderExportDefinition(MemberInfo member, string contractName, IDictionary<string, object> metadata)
            : base(contractName, metadata)
        {
            member
                .Require("member")
                .NotNull();

            contractName
                .Require("contractName")
                .NotNull()
                .NotEmpty();

            this.Member = member;
        }

        /// <summary>
        /// Gets the member that the export associated with.
        /// </summary>
        /// <value>A <see cref="MemberInfo"/> object.</value>
        public MemberInfo Member { get; private set; }
    }
}